package com.warm.base.jdk.thread.pool;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

/**
 * @Date: 2020/4/3 14:16
 * @Author: LChuang
 * @Description:
 */
public class Client {

    public static Executor executor = Executors.newFixedThreadPool(10);

    public static void main(String[] args) {
        // 自定义线程池
        MyExecutor myExecutor = new MyExecutor(5);
        Stream.iterate(1, item -> item + 1)
                .limit(10)
                .forEach(item -> {
                    myExecutor.execute(() -> {
                        try {
                            System.out.println(Thread.currentThread().getName() + " executor this task");
                            TimeUnit.SECONDS.sleep(2);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    });
                });

        // JUC Executor
        Stream.iterate(1, item -> item + 1).limit(20).forEach(item -> {
                    executor.execute(() -> {
                        System.out.println(Thread.currentThread().getName() + " hello!");
                    });
                }
        );

    }
}
